package com.duanxian.extend;

import de.felixroske.jfxsupport.SplashScreen;
import javafx.scene.Parent;
import javafx.scene.control.ProgressBar;
import javafx.scene.image.ImageView;
import javafx.scene.layout.VBox;

/**
 * 显示启动画面-扩展自定义,如果只是换图片，覆盖：/splash/javafx.png 路径即可
 * Created by llx on 2017/9/13.
 */
public class MySplashScreen extends SplashScreen{

    private static String DEFAULT_IMAGE = "/splash/javafx.png";

    /**
     * Override this to create your own splash pane parent node.
     *
     * @return A standard image
     */
    @Override
    public Parent getParent() {
        final ImageView imageView = new ImageView(getClass().getResource(getImagePath()).toExternalForm());
        final ProgressBar splashProgressBar = new ProgressBar();
        splashProgressBar.setPrefWidth(imageView.getImage().getWidth());

        final VBox vbox = new VBox();
        vbox.getChildren().addAll(imageView, splashProgressBar);

        return vbox;
    }

    /**
     * Customize if the splash screen should be visible at all.
     *
     * @return true by default
     */
    @Override
    public boolean visible() {
        return super.visible();
    }

    /**
     * Use your own splash image instead of the default one.
     *
     * @return "/splash/javafx.png"
     */
    @Override
    public String getImagePath() {
        return DEFAULT_IMAGE;
    }

    public void setImagePath(String path){
           this.DEFAULT_IMAGE = path;
    }
}
